package com.why.amallrest.controller;

import com.why.common.utils.PageUtils;
import com.why.common.utils.Result;
import com.why.entity.CategoryEntity;
import com.why.service.CategoryService;
import com.why.vo.CategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 商品分类
 *
 * @author why
 * @email 1585049082@qq.com
 * @date 2021-10-24 20:16:08
 */
@RestController
@RequestMapping("mall/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public Result list(){
        List<CategoryVo> vos = categoryService.queryList();
        return Result.ok().put("data", vos);
    }

    @RequestMapping("/category-product-recommends")
    public Result categoryRroductRecommends(){
        List<CategoryVo> vos = categoryService.queryCategoryProductRecommends();
        return Result.ok().put("data", vos);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{categoryId}")
  //  @RequiresPermissions("why:category:info")
    public Result info(@PathVariable("categoryId") Integer categoryId){
		CategoryEntity category = categoryService.getById(categoryId);

        return Result.ok().put("category", category);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
   /// @RequiresPermissions("why:category:save")
    public Result save(@RequestBody CategoryEntity category){
		categoryService.save(category);

        return Result.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
   // @RequiresPermissions("why:category:update")
    public Result update(@RequestBody CategoryEntity category){
		categoryService.updateById(category);

        return Result.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
   // @RequiresPermissions("why:category:delete")
    public Result delete(@RequestBody Integer[] categoryIds){
		categoryService.removeByIds(Arrays.asList(categoryIds));

        return Result.ok();
    }

}
